<template>
    <router-view v-if="loaded" />
</template>

<script>
import VConsole from 'vconsole';
import { mapActions } from 'vuex';
export default {
    computed: {
        needPreLoadUser() {
            return this.$route.name !== 'Test';
        },
        loaded() {
            return this.needPreLoadUser ? JSON.stringify(this.mztUser) !== '{}' : true;
        },
    },
    watch: {
        $route: {
            async handler(val) {
                let mock = this.$route.query.mock || this.$utils.getUrlParams('mock');
                // let scanFn = this.$route.query.scanFn || this.$utils.getUrlParams('scanFn')
                switch (val.name) {
                    // 单位注册
                    case 'SignForCorp':
                        // mock = "qyx";
                        break;
                }
                if (this.needPreLoadUser) {
                    await this.getMztUser(mock);
                    console.log('app', this.mztUser);
                }
            },
        },
    },
    async created() {
        let mode = this.$route.query.mode || this.$utils.getUrlParams('mode');
        if (
            process.env.NODE_ENV === 'development' ||
            process.env.NODE_ENV === 'preprod' ||
            mode === 'debug'
        ) {
            // 使用控制台输出模式
            new VConsole();
            console.log('Ver:20230215001');
        }
    },
    methods: {
        ...mapActions(['getMztUser']),
    },
};
</script>
